package trinnes.oliver.unimaas.smartpentalath.control;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import trinnes.oliver.unimaas.smartpentalath.data.Move;
import trinnes.oliver.unimaas.smartpentalath.data.Piece;

/**
 *
 * @author Oliver Trinnes
 */
public class RandomPlayer extends Player
{
  public RandomPlayer(Game game, Piece piece, String name, int ID)
  {
    super(game, piece, name, ID);
  }

  @Override
  public int getNextMove()
  {
    long start = System.currentTimeMillis();
    while(System.currentTimeMillis() - start < 3000)
    {
      try
      {
        Thread.sleep(100);
      }
      catch(InterruptedException ex)
      {
        Logger.getLogger(HumanPlayer.class.getName()).log(Level.SEVERE, null, ex);
      }
      if(nextMoveChanged)
      {
        nextMoveChanged = false;
        return Move.UNDO;
      }
    }
    List<Integer> possibleMoves = getGame().getPossibleMoves(getPiece());
    int randomIndex = (int)(Math.random() * possibleMoves.size());
    return possibleMoves.get(randomIndex);
  }

}
